package test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import calculater.Button;

public class test_Button {

	@Test
	public void test_number() {
		Button b = new Button();
		assertEquals("0", b.number("", "0"));
		assertEquals("1", b.number("0", "1"));
		assertEquals("( 1", b.number("( 0", "1"));
		assertEquals("0.1", b.number("0.", "1"));
		assertEquals("1 + 2", b.number("1 +", "2"));
		assertEquals("( 0", b.number("(", "0"));
		assertEquals(")", b.number(")", "0"));
		assertEquals("10", b.number("1", "0"));
	}
	
	@Test
	public void test_operator() {
		Button b = new Button();
		assertEquals("", b.operator("", "+"));
		assertEquals("0 +", b.operator("0.", "+"));
		assertEquals("1 +", b.operator("1 +", "+"));
		assertEquals("1 +", b.operator("1", "+"));
		assertEquals("(", b.operator("(", "+"));
		assertEquals(") +", b.operator(")", "+"));
	}
	
	@Test
	public void test_left_par() {
		Button b = new Button();
		assertEquals("(", b.left_par(""));
		assertEquals("0.", b.left_par("0."));
		assertEquals("1 + (", b.left_par("1 +"));
		assertEquals("1", b.left_par("1"));
		assertEquals("( (", b.left_par("("));
		assertEquals(")", b.left_par(")"));
	}
	
	@Test
	public void test_right_par() {
		Button b = new Button();
		assertEquals("", b.right_par(""));
		assertEquals("( 0 )", b.right_par("( 0."));
		assertEquals("1 +", b.right_par("1 +"));
		assertEquals("1", b.right_par("1"));
		assertEquals("", b.right_par("("));
		assertEquals("", b.right_par(""));
		assertEquals("( ( 1 ) )", b.right_par("( ( 1 )"));
	}
	
	@Test
	public void test_caculate() {
		Button b = new Button();
		assertEquals("3", b.caculate("1 + 2"));
		assertEquals("7", b.caculate("1 + 2 * 3"));
		assertEquals("inf", b.caculate("1 / 0"));
		assertEquals("8", b.caculate("2 * ( 1 + 3 )"));
		assertEquals("0", b.caculate(""));
		assertEquals("-2", b.caculate("-1 - 1"));
	}
	
	@Test
	public void test_point() {
		Button b = new Button();
		assertEquals("0.", b.point(""));
		assertEquals("0.", b.point("0"));
		assertEquals("0 + 0.", b.point("0 +"));
		assertEquals("0.1", b.point("0.1"));
		assertEquals("0.", b.point("0."));
		assertEquals("( 0 )", b.point("( 0 )"));
		assertEquals("( 0.", b.point("("));
	}
	
	@Test
	public void test_check() {
		Button b = new Button();
		assertEquals("( ( ) )", b.check("( ("));
		assertEquals("( 0 )", b.check("( 0."));
		assertEquals("0", b.check("0 +"));
	}
	
}
